//
// Created by Vinson Cai on 2020/5/4.
//

#ifndef AIRPLAYLIBRARY_DEFAULTSETTING_H
#define AIRPLAYLIBRARY_DEFAULTSETTING_H
#ifdef __cplusplus
extern "C" {
#endif  /* __cplusplus */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

#include "AirplayReceiver.h"



//url:视频地址
//fPosition:视频百分比断点
//dPosition:视频秒数断点(x1000)
void defaultAirplayOpenUrl(void *cls, const char* ip, char *url, double fPosition, double dPosition){
    (void) cls;
    (void) ip;
    (void) url;
    (void) fPosition;
    (void) dPosition;
}

void defaultAirplayOpenDoubleUrl(void *cls, const char* ip, char *videoUrl,char *audioUrl, double fPosition, double dPosition){
    (void) cls;
    (void) ip;
    (void) videoUrl;
    (void) audioUrl;
    (void) fPosition;
    (void) dPosition;
}

void defaultAirplayPlayerPlay(void *cls, const char* ip){
    (void) cls;
    (void) ip;
}

void defaultAirplayPause(void *cls, const char* ip){
    (void) cls;
    (void) ip;
}


void defaultAirplayStopPlayback(void *cls, const char* ip){
    (void) cls;
    (void) ip;
}

void defaultAirplayRemovePlayback(void *cls, const char* ip){
    (void) cls;
    (void) ip;
}

void defaultAirplaySeek(void *cls, const char* ip, long fPosition){
    (void) cls;
    (void) ip;
    (void) fPosition;
}


void defaultAirplaySetvolume(void *cls, const char* ip, int volume){
    (void) cls;
    (void) ip;
    (void) volume;
}
void defaultAirplayShowphoto(void *cls, const char* ip, unsigned char *data, long long size){
    (void) cls;
    (void) ip;
    (void) data;
    (void) size;
}
long defaultAirplayGetDuration(void *cls, const char* ip){
    (void) cls;
    (void) ip;

    return 1000;
}
long defaultAirplayGetPostion(void *cls, const char* ip){
    (void) cls;
    (void) ip;

    return 500;
}
int defaultAirplayIsPlaying(void *cls, const char* ip){
    (void) cls;
    (void) ip;

    return 1;
}
int defaultAirplayIsPaused(void *cls, const char* ip){
    (void) cls;
    (void) ip;
    return 0;
}

void defaultAudioInit(void *cls, const char* ip, int bits, int channels, int samplerate, int isaudio){
    (void) cls;
    (void) ip;
    (void) bits;
    (void) channels;
    (void) samplerate;
    (void) isaudio;
}
void defaultAudioProcess(void *cls, const char* ip, const void *buffer, int buflen, uint64_t timestamp, uint32_t seqnum){
    (void) cls;
    (void) ip;
    (void) buffer;
    (void) buflen;
    (void) timestamp;
    (void) seqnum;
}
void defaultAudioDestory(void *cls, const char* ip){
    (void) cls;
    (void) ip;
}
void defaultAudioSetvolume(void *cls, const char* ip, float volume){
    (void) cls;
    (void) ip;
    (void) volume;
}
void defaultAudioSetMetadata(void *cls, const char* ip, const void *buffer, int buflen){
    (void) cls;
    (void) ip;
    (void) buffer;
    (void) buflen;
}
void defaultAudioSetCoverArt(void *cls, const char* ip, const void *buffer, int buflen){
    (void) cls;
    (void) ip;
    (void) buffer;
    (void) buflen;
}
void defaultAudioFlush(void *cls, const char* ip){
    (void) cls;
    (void) ip;
}

void defaultAirplayCreateConnection(void *cls, const char* ip) {
    (void) cls;
    (void) ip;
}

void defaultAirplayTearDownConnection(void *cls, const char* ip) {
    (void) cls;
    (void) ip;
}

//视频开始播放设置
void defaultAirplayVideoMirrorStart(void *cls, const char* ip){
    (void) cls;
    (void) ip;
}

//视频流播放
void defaultAirplayVideoMirrorFrame(void *cls, const char* ip, const unsigned char *buffer, int buflen, uint64_t timestamp){
    (void) cls;
    (void) ip;
    (void) buffer;
    (void) buflen;
    (void) timestamp;
}

//视频停止回调
void defaultAirplayVideoMirrorStop(void *cls, const char* ip){
    (void) cls;
    (void) ip;
}


//镜像心跳检测
void defaultMirroringLive(void *cls, const char* ip){
    (void) cls;
    (void) ip;
}

void defaultAirplayUpdateDeviceInformation(void* cls, const char* ip, const char* name,const AirplayDeviceModel model) {
    (void) cls;
    (void) ip;
    (void) name;
    (void) model;
}

void defaultAirplayLog(const char* msg) {
    (void) msg;
}

void defaultAirplayActivateSuccess(const char* secret) {
    (void) secret;
}

void defaultAirplayAuthActivateSuccess(void *cls,const char* ip,const char* password){
    (void)cls;
    (void)ip;
    (void)password;
}

void defaultAirplayAuthActivateFail(void *cls,const char* ip,const char* password){
    (void)cls;
    (void)ip;
    (void)password;
}

void defaultAirplayAuthActivating(void *cls,const char* ip,const char* password){
    (void)cls;
    (void)ip;
    (void)password;
}

void defaultAirplayAuthAllowConnectRequestStart(void *cls,const char* ip){
    (void)cls;
    (void)ip;
}

void defaultAirplayAuthAllowConnectRequesting(void *cls,const char* ip,AirplayAuthAllowStatus* status){
    (void)cls;
    (void)ip;
    *status=AIRPLAY_AUTH_ALLOW_ACCEPT;
}

void defaultAirplayAuthAllowConnectRequestTimeout(void *cls,const char* ip){
    (void)cls;
    (void)ip;
}

static airplay_callbacks_t GetDefaultFunctions(void)
{
    airplay_callbacks_t cbs;

    cbs.airplay_connection_create       = defaultAirplayCreateConnection;
    cbs.airplay_connection_teardown     = defaultAirplayTearDownConnection;

    cbs.AirPlayPlayback_Open			= defaultAirplayOpenUrl;
    cbs.AirPlayPlaybackDouble_Open      = defaultAirplayOpenDoubleUrl;
    cbs.AirPlayPlayback_Play			= defaultAirplayPlayerPlay;
    cbs.AirPlayPlayback_Pause		    = defaultAirplayPause;
    cbs.AirPlayPlayback_Stop			= defaultAirplayStopPlayback;
    cbs.AirplayPlayback_remove          = defaultAirplayRemovePlayback;
    cbs.AirPlayPlayback_Seek			= defaultAirplaySeek;
    cbs.AirPlayPlayback_SetVolume	    = defaultAirplaySetvolume;
    cbs.AirPlayPlayback_ShowPhoto	    = defaultAirplayShowphoto;
    cbs.AirPlayPlayback_GetDuration	    = defaultAirplayGetDuration;
    cbs.AirPlayPlayback_GetPosition     = defaultAirplayGetPostion;
    cbs.AirPlayPlayback_IsPlaying	    = defaultAirplayIsPlaying;
    cbs.AirPlayPlayback_IsPaused		= defaultAirplayIsPaused;
    //...
    cbs.AirPlayAudio_Init			    = defaultAudioInit;
    cbs.AirPlayAudio_Process			= defaultAudioProcess;
    cbs.AirPlayAudio_destroy			= defaultAudioDestory;
    cbs.AirPlayAudio_SetVolume		    = defaultAudioSetvolume;
    cbs.AirPlayAudio_SetMetadata		= defaultAudioSetMetadata;
    cbs.AirPlayAudio_SetCovertArt		= defaultAudioSetCoverArt;
    cbs.AirPlayAudio_Flush			    = defaultAudioFlush;
    //...
    cbs.AirPlayMirroring_start		    = defaultAirplayVideoMirrorStart;
    cbs.AirPlayMirroring_Process		= defaultAirplayVideoMirrorFrame;
    cbs.AirPlayMirroring_Stop		    = defaultAirplayVideoMirrorStop;
    cbs.AirPlayMirroring_Live		    = defaultMirroringLive;

    cbs.AirplayUpdateDeviceInformation  = defaultAirplayUpdateDeviceInformation;
    cbs.airplay_log_callback            = defaultAirplayLog;
    cbs.airplay_activate_success        = defaultAirplayActivateSuccess;

    cbs.AirplayAuthActivateSuccess      = defaultAirplayAuthActivateSuccess;
    cbs.AirplayAuthActivating           = defaultAirplayAuthActivating;
    cbs.AirplayAuthActivateFail         = defaultAirplayAuthActivateFail;

    cbs.AirplayAuthAllowConnectRequestStart = defaultAirplayAuthAllowConnectRequestStart;
    cbs.AirplayAuthAllowConnectRequesting   = defaultAirplayAuthAllowConnectRequesting;
    cbs.AirplayAuthAllowConnectRequestTimeout = defaultAirplayAuthAllowConnectRequestTimeout;

    return cbs;
}



static airplay_parameter_t GetDefaultParameters(void)
{
    airplay_parameter_t params;

    srand(time(0));
    int id = rand() % 256;

    sprintf(params.name, "Airplay %02X", id);
    strcpy(params.password, "");

    params.activateInterface = AIRPLAY_INTERFACE_ETHERNET;
    strcpy(params.activateCode, "");
    strcpy(params.activateSecret, "");
    strcpy(params.customerCode, "TRIAL_MEETING");
    strcpy(params.platformType, "TEST_MACHINE");

    params.airplayResolution = AIRPLAY_RESOLUTION_720;
    params.discoverable = true;
    params.targetFps = 30;
    params.supportUrl = 1;
    params.selfAnnounce = false;
    //0表示由系统判断超时时间，大于0则使用自己设置的
    params.checkTimeoutTime = 0;
    params.airplayOrientation = AIRPLAY_ORIENTATION_LANDSCAPE;

    return params;
}



#ifdef __cplusplus
}
#endif  /* __cplusplus */






#endif //AIRPLAYLIBRARY_DEFAULTSETTING_H
